package com.charactereducation.pitchpalace.controller.api;

import com.charactereducation.module.vo.User;
import com.charactereducation.pitchpalace.service.UserService;
import com.charactereducation.tools.result.ResultObj;
import com.charactereducation.webcore.controller.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * Created by Baggio on 2018-6-25.
 */
@RestController
@RequestMapping("/api/user")
public class UserController extends BaseController {
    @Autowired
    UserService userService;

    @GetMapping(value = "/{id}")
    public ResultObj get(@PathVariable("id") Long id) {
        logger.info("getUserById");
        ResultObj resultObj = new ResultObj();
        User user = userService.getUserById(id);
        resultObj.setData(user);
        return resultObj;
    }

    @PostMapping("/modify")
    public void modify(@RequestParam User user) {

        userService.modifyUser(user);


    }

    @GetMapping("/smsCode")
    public ResultObj smsCode(String phone) {

        String code = userService.getSMSCode(phone);

        ResultObj resultObj = new ResultObj();
        resultObj.setData(code);
        return resultObj;
    }

}
